package app.controller.sys;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import app.model.sys.SysRole;
import app.service.sys.SysRoleMenuService;
import app.service.sys.SysRoleService;
import base.JsonResult;
import base.PageInfo;

@Controller
@RequestMapping("/sys/role")
public class SysRoleController {
	
	@Resource
	private SysRoleService sysRoleService;
	
	@Resource
	private SysRoleMenuService sysRoleMenuService;

	@ResponseBody
	@RequestMapping("/query.do")
	public PageInfo query(PageInfo pageInfo){
		return sysRoleService.queryPageList(pageInfo);
	}
	
	@ResponseBody
	@RequestMapping("/save.do")
	public JsonResult save(SysRole sysRole){
		if(StringUtils.isEmpty(sysRole.getId())){
			sysRoleService.saveEntity(sysRole);
		}else{
			sysRoleService.updateEntity(sysRole);
		}
		return new JsonResult("操作成功");
	}
	
	@ResponseBody
	@RequestMapping("/view.do")
	public JsonResult view(String id){
		SysRole sysRole = sysRoleService.queryEntityById(id);
		return new JsonResult("操作成功",sysRole);
	}
	
	@ResponseBody
	@RequestMapping("/del.do")
	public JsonResult del(String ids){
		sysRoleService.delEntity(ids);
		return new JsonResult("操作成功");
	}
	
	@ResponseBody
	@RequestMapping("/saveSysRoleMenu.do")
	public JsonResult saveSysRoleMenu(String menuIds,String roleId){
		try {
			sysRoleMenuService.saveSysRoleMenu(menuIds,roleId);
			return new JsonResult("操作成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new JsonResult("操作失败",false);
		}
		
	}
}
